import VueRouter from 'vue-router'
import Home from './pages/Home.vue'
import Account from './pages/Account.vue'
import User_info from './pages/User_info.vue'
import Projects from './pages/Projects.vue'
import Edit from './pages/Edit.vue'
import Workbench from './pages/Workbench.vue'
import Demo from './pages/Demo.vue'
import login from './components/login.vue'
import register from './components/register.vue'

import Vue from 'vue'

Vue.use(VueRouter)

// 解决vue-router在跳转当前页的报错
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
  return originalPush.call(this, location).catch(err => err)
}


const routes = [
  { path: '/', redirect: '/account' },
  { path: '/demo', component: Demo },
  { 
    path: '/home', 
    component: Home,
    redirect:'/home/projects',
    children: [
      { path: 'user_info', component: User_info },
      { path: 'projects', component: Projects },
      { path: 'edit', component: Edit },
      { path: 'workbench', component: Workbench }
    ]
   },
  {
    path: '/account', 
    component: Account,
    redirect:'/account/login',
    children: [
      { path: 'login', component: login },
      { path: 'register', component: register }
    ]
  }
]


export default new VueRouter({
  routes
})

